/* 
 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
 * All rights reserved.
 *
 */

#ifndef _MB_APP_H
#define _MB_APP_H

#include "mbcom.h"
#include "qcom.h"
#include "mb_box_input.h"

#ifdef _MAPP_MODULE_
#define MAPP_EXT
#else
#define MAPP_EXT extern
#endif

#define MBAPP_EVENT_MSK 0xFFFFUL

/******************************************************************************
 * @brief   modbus manager
 *****************************************************************************/
typedef struct
{
	qc_obj_type qc01;
	qc_cmd_type qc_cmd01[16];
	qc_obj_type qc02;
	qc_cmd_type qc_cmd02[16];
	qc_obj_type qc03;
	qc_cmd_type qc_cmd03[16];
	qc_obj_type qc04;
	qc_cmd_type qc_cmd04[16];
	qc_obj_type qc05;
	qc_cmd_type qc_cmd05[16];
	qc_obj_type qc06;
	qc_cmd_type qc_cmd06[16];
	qc_obj_type qc08;
	qc_cmd_type qc_cmd08[16];
} mb_type;

MAPP_EXT mb_type mb;

/******************************************************************************
 * @brief   mb init
 *****************************************************************************/
void mb00_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb00_TimeoutHandle(void);

void mb01_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb01_TimeoutHandle(void);

void mb02_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb02_TimeoutHandle(void);

void mb03_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb03_TimeoutHandle(void);

void mb04_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb04_TimeoutHandle(void);

void mb05_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb05_TimeoutHandle(void);

void mb06_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb06_TimeoutHandle(void);

void mb07_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb07_TimeoutHandle(void);

void mb08_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity);
void mb08_TimeoutHandle(void);

/******************************************************************************
 * @brief   qc init
 *****************************************************************************/
void qc01_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc02_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc03_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc04_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc05_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc06_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc07_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);
void qc08_Init(uu08 qcMode, uint32_t ulBaudRate, mb_parity_type eParity);

/******************************************************************************
 * @brief   os event send
 *****************************************************************************/
void mb0_os_event_send(uint16_t event);
void mb1_os_event_send(uint16_t event);
void mb2_os_event_send(uint16_t event);
void mb3_os_event_send(uint16_t event);
void mb4_os_event_send(uint16_t event);
void mb5_os_event_send(uint16_t event);
void mb6_os_event_send(uint16_t event);
void mb7_os_event_send(uint16_t event);
void mb8_os_event_send(uint16_t event);

/******************************************************************************
 * @brief   qc slave api
 *****************************************************************************/
uint16_t qc_reg_get(uint16_t Index);
void qc_reg_set(uint16_t Index, uint16_t Val);
uint16_t qc_input_get(uint16_t Index);
void qc_coil_dat_set(uu16 Bindex, uu8 dat);
uu8 qc_coil_dat_get(uu16 Bindex);

uint16_t box_qc_reg_get(uint16_t Index);
void box_qc_reg_set(uint16_t Index, uint16_t Val);
uint16_t box_qc_input_get(uint16_t Index);
void box_qc_coil_dat_set(uu16 Bindex, uu8 dat);
uu8 box_qc_coil_dat_get(uu16 Bindex);


extern qc_com_slave_type qc_com_slave_basic;
extern qc_mb_slave_type qc_mb_slave_basic;

extern qc_com_slave_type qc_com_slave_box;
extern qc_mb_slave_type qc_mb_slave_box;


#undef MAPP_EXT

#endif
